package math

import (
	"jvm/instructions/base"
	"jvm/rtda"
)

// Increment local variable by constant
type IINC struct {
	Index uint
	Const int32
}

func (ii *IINC) FetchOperands(reader *base.BytecodeReader) {
	ii.Index = uint(reader.ReadUint8())
	ii.Const = int32(reader.ReadInt8())
}

func (ii *IINC) Execute(jFrame *rtda.JFrame) {
	localVars := jFrame.LocalVars()
	val := localVars.GetInt(ii.Index)
	val += ii.Const
	localVars.SetInt(ii.Index, val)
}
